<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app"></div>
  <script>
    if (window.Worker) {
      //new worker 后端线程
      var work = new Worker("./bg_worker.js");
      //向后端线程发送数据
      work.postMessage(100);
      //接收后端线程传过来的数据
      work.addEventListener('message', (result) => {
        document.getElementById("app").innerHTML = result.data;
        if (result.data > 2000) {
          //停止线程
          work.terminate();
        }
      })

    }
  </script>
</body>
</html>